﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<BadmintonBuddy.Models.Club>>" %>
<%@ Import Namespace="BadmintonBuddy.Helpers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Badminton Courts in <%: ViewData["q"] %>,Badminton Clubs in <%: ViewData["q"] %>,Play Badminton in <%: ViewData["q"] %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
    function LoadSearchPins() {        
        //Load pins as obtained in the Model.
        count = 0;
       <%foreach(var item in Model) {%>            
            var letter = String.fromCharCode("A".charCodeAt(0) + count);
            var letteredIcon = new GIcon(G_DEFAULT_ICON);            
            letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
            //letteredIcon.image = "http://google-maps-icons.googlecode.com/files/red" + count+1 + ".png";

            // Set up our GMarkerOptions object
            markerOptions = { icon: letteredIcon };
            var latlng = new GLatLng(<%=item.Latitude %>,<%= item.Longitude %>);
            var gmarker = new GMarker(latlng, markerOptions);            
            GEvent.addListener(gmarker, "click", function() {
                gmarker.openInfoWindowHtml("<b>Club : <%= item.ClubName %></b><p><b>Address : <%= item.Address  %>,<%= item.City.CityName %></b></p><span class=\"space\"><a href=\"Details/<%= item.ClubName %>\">More Info</a></span>||<span class=\"space\"><a href=\"http://maps.google.com/maps?daddr=<%=item.Latitude  %>,<%= item.Longitude %>&saddr=\" target=\"_blank\">Directions</a></span>");                
            });
            map.addOverlay(gmarker);
            if(count == 0){         //set the first point as the center of the map.
                map.setCenter(latlng,11);
            }
            $('#'+count+'').html("<img src=\""+letteredIcon.image+"\" alt=\"marker\"/>");
            count++;
       <%} %>       
       map.setUIToDefault();       
    }        
    </script>
    <% Html.RenderPartial("SearchForm", Model); %>
    <div id="info">
        <b></b>
    </div>
    <div id="results">
        <div id="mapDiv" style="height: 500px; width: 500px; float: left;">
        </div>
        <div id="showresults" class="showresults">
            <% if (Model.Count() == 0)
               {  %>
            <div class="noresult">
                <div class="red">
                    No clubs found for "<%: ViewData["q"] %>"
                </div>
                <% Html.RenderAction("TagCloud"); %>
                <%--<div class="noresultbut">
                    <div class="grn button mt25">
                        <a href="/Index" class="green" title="Check all clubs in our list"><b>Browse All Clubs»</b></a>
                    </div>
                </div>--%>
                <div>
                    Know any clubs in "<%: ViewData["q"] %>", <a href="Create">please add to the list</a> and help improve baminton community.
                </div>
            </div>
            <%} %>
            <div class="results">
                <% int count = 0; %>
                <% foreach (var item in Model)
                   {%>
                <% var clubName = item.ClubName.Replace(" ", "-");%>
                <div class="clubresults">
                    <div class="floatl mart5" id="<%:count %>">
                    </div>
                    <span class="name"><a href="Details/<%: item.ClubName %>">
                        <%: item.ClubName %></a></span>
                    <div class="address">
                        <%: item.Address %>
                        <div>
                            <%: item.City.CityName %>,<%: item.City.State.StateName %>-<%: item.Zipcode %></div>
                    </div>
                    <div class="buttonresult">
                        <a class="green" href="Details/<%: item.ClubName %>">More info»</a>
                    </div>
                </div>
                <% count++; %>
                <% } %>
            </div>
        </div>
    </div>
    <div class="dispn report">
        <textarea id="report" cols="40" rows="5"></textarea>
    </div>
    <div id="SearchPage">
    </div>
</asp:Content>
<asp:Content ContentPlaceHolderID="Footer" runat="server">
    <%= Html.RenderScript("../../Scripts/Map.js") %>
</asp:Content>
